//Tok_v_vitke
//Borovov A.
//2101
//17.12.12

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <windows.h>
#include <graphics.h>
#include <stdlib.h>

using namespace std;

const double pi=3.14159265,nu=1.25663706;

class I
{
public:
    double xI,yI;
    double realtI(double IoP,double t0P,double wP)
    {
        return IoP*cos(wP*t0P);
    }
    double tI(double IoP,double kcosP,double t0P)
    {
        return IoP*cos(kcosP*t0P);
    }
    ~I()
    {
        xI=0;yI=0;
    }
};

class B
{
public:
    double xB,yB;
    double realtB(double tP,double rIP)
    {
        return (1/tP)*rIP;
    }    
    double tBx(double kpP,double tP,double rBP)
    {
        return (kpP/tP)*rBP;
    }    
    double tBy(double IoP,double rOP,double rIP)
    {
        return (IoP/rOP)*rIP;
    }
    ~B()
    {
        xB=0;yB=0;
    }
};

class obsh
{
public:
    double Zn,ind,kolpix,koldel,xO,yO;
    int aC,bC,cC;
    double realtO(double kP,double t0P,double rP)
    {
        return -kP*t0P+rP;
    }
    obsh()
    {
        aC=35;bC=635;cC=2;
        ind=9000;
    }
    ~obsh()
    {
        Zn=0;ind=0;kolpix=0;koldel=0;xO=0;yO=0;ind=0;
        aC=0;bC=0;cC=0;
    }
};

//______________________________________________________________________________
main()
{  
    int i,ySech,d,xSech;
    double t,Io,k,k0,t0,maxA,kcos;
    I tchkImass[10000],realtImass[10000],If;
    B tchkBmass[10000],realtBmass[10000],Bf;
    obsh tC,wC,rC,IoC,T,I,rKC,tchkOmass[10000],realtOm[10000],inti,Of;
    float xPodp,yPodpI,yPodpB,yPodpL,xPodp1;
    char txt[10];
    string txt1;
    
    //ispols_stand_znach
    cout<<"use standart values?:"<<endl;
    cin>>txt1;
    if(txt1=="y")
    {
        wC.Zn=10;tC.Zn=40;rC.Zn=10;rKC.Zn=0.1;IoC.Zn=100;
    }
    else
    {
        cout<<"w:"<<endl;
        cin>>wC.Zn;
        cout<<endl<<"t:"<<endl;
        cin>>tC.Zn;
        cout<<endl<<"rs:"<<endl;
        cin>>rC.Zn;
        cout<<endl<<"rf:"<<endl;
        cin>>rKC.Zn;
        cout<<endl<<"A:"<<endl;
        cin>>IoC.Zn;
    }
    
    T.kolpix=500;I.kolpix=180;Io=I.kolpix;
    T.koldel=20;I.koldel=9;
    k=(rC.Zn-rKC.Zn)/tC.Zn;
    kcos=(2*inti.cC*pi)/500;
    
    //cikl_dlya_per
    for(i=1,t=0,t0=0;i<=T.ind;i++,t+=(T.kolpix/T.ind))
    {
        tchkImass[i].xI=t;
        tchkImass[i].yI=If.tI(Io,kcos,t);
    }
    
    //real_chisl
    maxA=0;
    for(i=1,t0=0;t0<=tC.Zn;i++,t0+=0.01)
    {
        realtImass[i].xI=t0;
        realtImass[i].yI=If.realtI(IoC.Zn,t0,wC.Zn);
        realtOm[i].yO=Of.realtO(k,t0,rC.Zn);
        realtBmass[i].xB=t0;
        realtBmass[i].yB=Bf.realtB(realtOm[i].yO,realtImass[i].yI);
        if(abs(int(realtBmass[i].yB))>maxA)
            maxA=abs(int(realtBmass[i].yB));
        
        tchkBmass[i].xB=Bf.tBx(T.kolpix,tC.Zn,realtBmass[i].xB);
    }
    
    Io=I.kolpix/maxA;
    for(d=1;d<=i;d++)
        tchkBmass[d].yB=Bf.tBy(Io,realtOm[d].yO,realtImass[d].yI);
    
//Graph_________________________________________________________________________
    initwindow(1200,800);
    
    moveto(inti.aC,200);
    lineto(inti.bC-60,200);
    moveto(inti.aC,20);
    lineto(inti.aC,380);
    
    moveto(inti.bC,200);
    lineto(inti.bC+540,200);
    moveto(inti.bC,20);
    lineto(inti.bC,380);
    
    moveto(inti.aC,600);
    lineto(inti.bC-60,600);
    moveto(inti.aC,780);
    lineto(inti.aC,420);
    
    //Sechki+txt
    settextstyle(3,0,1);  
    outtextxy(inti.aC+5,10,"I(t)");
    outtextxy(inti.bC+5,10,"r(t)");
    outtextxy(inti.aC+5,410,"B(t)");
    outtextxy(inti.bC-60,180,"t");
    outtextxy(inti.bC-60,580,"t");
    outtextxy(inti.bC+540,180,"t");
    
    settextstyle(2,0,5);
    for(i=1,ySech=0,yPodpI=(-IoC.Zn),yPodpL=rKC.Zn,
    yPodpB=(-maxA*nu)/(4*pi*rC.Zn);i<=19;i++,ySech+=20,
    yPodpI+=(IoC.Zn/I.koldel),yPodpL+=((rC.Zn-rKC.Zn)/18),
    yPodpB+=(maxA*nu)/(4*pi*rC.Zn*I.koldel))
    {
        moveto(inti.aC+3,380-ySech);
        lineto(inti.aC-3,380-ySech);
        moveto(inti.bC+3,380-ySech);
        lineto(inti.bC-3,380-ySech);
        moveto(inti.aC+3,780-ySech);
        lineto(inti.aC-3,780-ySech);
        
        sprintf(txt,"%1.1f",yPodpI);
        outtextxy(inti.aC-30,375-ySech,txt);
        sprintf(txt,"%1.1f",yPodpL);
        outtextxy(inti.bC-30,375-ySech,txt);
        
        sprintf(txt,"%1.1f",yPodpB);
        outtextxy(inti.aC-30,775-ySech,txt);
    }

    for(i=1,xSech=35,xPodp=(tC.Zn/T.koldel),xPodp1=((2*pi*inti.cC)/(wC.Zn*T.koldel));
    i<=T.koldel;i++,xSech+=25,xPodp+=(tC.Zn/T.koldel),
    xPodp1+=((2*pi*inti.cC)/(wC.Zn*T.koldel)))
    {
        moveto(xSech+25,203);
        lineto(xSech+25,197);
        moveto(xSech-15+inti.bC,203);
        lineto(xSech-15+inti.bC,197);
        moveto(xSech+25,603);
        lineto(xSech+25,597);
        
        sprintf(txt,"%1.1f",xPodp1);
        outtextxy(xSech+15,204,txt);
        sprintf(txt,"%1.1f",xPodp);
        outtextxy(xSech+15,604,txt);
        outtextxy(xSech-25+inti.bC,204,txt);
    }
//______________________________________________________________________________      
    
    //SinI
    moveto(inti.aC,200);
    for(i=1;i<=T.ind;i++)
    {
        lineto(int(tchkImass[i].xI)+inti.aC,int(tchkImass[i].yI)+200);
        moveto(int(tchkImass[i].xI)+inti.aC,int(tchkImass[i].yI)+200);
    }
    
    moveto(inti.bC,20);
    lineto(inti.bC+500,380);
    /*//Lin
    moveto(b,20);
    for(i=1;i<=T.ind;i++)
    {
        lineto(int(tchkOmass[i].xO)+b,int(tchkOmass[i].yO)+20);
        moveto(int(tchkOmass[i].xO)+b,int(tchkOmass[i].yO)+20);
    }*/
    
    //SinB
    moveto(inti.aC,600);
    for(i=1;i<=T.ind;i++)
    {
        lineto(int(tchkBmass[i].xB)+inti.aC,int(tchkBmass[i].yB)+600);
        moveto(int(tchkBmass[i].xB)+inti.aC,int(tchkBmass[i].yB)+600);
    }
        
  
    system("pause");
    closegraph();
    
    
    return 0;
}//_____________________________________________________________________________
